from ys_python.common.mq import GRPCMQ

__topics = [
    "json.web",
    "weather",
    "stocks.GOOG",
    "sports.basketball",
]


def subprocess(id_: int):
    mq: GRPCMQ = GRPCMQ()
    queue = mq.subscribe(__topics[id_])
    while True:
        msg = queue.get()
        print("[id:{}][{}] {}".format(id_, msg.topic, msg.message))


if __name__ == '__main__':
    subprocess(0)
    # processes = []
    # for i in range(4):
    #     processes.append(multiprocessing.Process(target=subprocess, kwargs={"id_": i}))
    #
    # for process in processes:
    #     process.start()
    #
    # for process in processes:
    #     process.join()
